// Set 数据结构
<template>
  <div>
    <prism language="javascript">
      let s = new Set();
      s.add("yuan");
      s.add("lei");
      s.add("lei");
      s.add(808);
      console.log(s);
      console.log(s.size); //不能用length，只能用size

      for (let i of s) {
      console.log(i);
      }
      s.forEach(v => {
      console.log(v);
      });
      let ns = [...s].map(v => v + 1); //map函数只能是将set变成数组才能进行操作
      console.log(ns);
      //set没有map方法
      console.log(new Set("aaaabbbbcc"));
      //set的参数是字符串时，就会生成一个一个set（把每个位置加到set中）

      //数组去重复
      var arr = [1, 2, 3, 4, , 1, 2, 3, 4, 7];
      var na = Array.from(new Set(arr)); //或者
      var na1 = [...new Set(arr)];
      console.log(na, na1);

      let fs = [...s].filter(v => isNaN(v));
      let fs1 = [...s].filter(v => !isNaN(v));
      console.log(fs, fs1);

      console.log(s.has("yuan")); //判断s中有“yuan”这个成员
      s.delete("yuan");
    </prism>
    <v-btn
      round
      color="success"
      @click="run"
    >
      RUN
    </v-btn>
  </div>
</template>

<script>
import Prism from "vue-prism-component";
export default {
  components: {
    Prism
  },
  methods: {
    run() {
      let s = new Set();
      s.add("yuan");
      s.add("lei");
      s.add("lei");
      s.add(808);
      console.log(s);
      console.log(s.size); //不能用length，只能用size

      for (let i of s) {
        console.log(i);
      }
      s.forEach(v => {
        console.log(v);
      });
      let ns = [...s].map(v => v + 1); //map函数只能是将set变成数组才能进行操作
      console.log(ns);
      //set没有map方法
      console.log(new Set("aaaabbbbcc"));
      //set的参数是字符串时，就会生成一个一个set（把每个位置加到set中）

      //数组去重复
      var arr = [1, 2, 3, 4, , 1, 2, 3, 4, 7];
      var na = Array.from(new Set(arr)); //或者
      var na1 = [...new Set(arr)];
      console.log(na, na1);

      let fs = [...s].filter(v => isNaN(v));
      let fs1 = [...s].filter(v => !isNaN(v));
      console.log(fs, fs1);

      console.log(s.has("yuan")); //判断s中有“yuan”这个成员
      s.delete("yuan");
    }
  }
};
</script>